<?php defined('SYSPATH') or die('No direct script access.');

class Controller_Admin_Auth extends Controller_Admin {
    public $template = 'admin_auth/index';
    
    public function action_index()
    {
        $post = $this->request->post();
        if (isset($post['username'], $post['password']))
        {
           
            $logged = Auth::instance()->login($post['username'], $post['password']);
            
            if ($logged)
            {
                   if (Auth::instance()->logged_in('admin'))
                    {
                            HTTP::redirect('admin');
                    }
                    else if (Auth::instance()->logged_in('doctor')){
                            HTTP::redirect('user_doctor');
                    }
            }
            
            $this->template->error = 'Złe dane';
        }
     }
     
     public function action_register()
     {
         HTTP::redirect('register');
     }
     
     public function action_logout()
     {
         Auth::instance()->logout();
         HTTP::redirect();
     }

}          
